﻿using System;
using System.Collections.Generic;

namespace Cypher.Sample.WebAPI.Repositories
{
	class ProductsRepository : IProductsRepository
	{
		#region Fields

		/// <summary>
		/// Initialize a bag of products
		/// </summary>
		private readonly IList<dynamic> _products = new List<dynamic> 
			{
				new { id=1, description="My description of product 1"},
				new { id=2, description="My description of product 2"},
				new { id=3, description="My description of product 3"},
				new { id=4, description="My description of product 4"},
				new { id=5, description="My description of product 5"},
			};

		#endregion		

		#region IProductsRepository Members

		/// <summary>
		/// Gets a list of products
		/// </summary>
		/// <returns>A list of products</returns>
		public IEnumerable<dynamic> GetProducts()
		{
			return this._products;
		}

		/// <summary>
		/// Gets a products
		/// </summary>
		/// <param name="id">the id of the product</param>
		/// <returns>A product</returns>
		public dynamic GetProduct(int id)
		{
			if (id > 0 && id < _products.Count)
			{
				return this._products[id -1];
			}

			return new { };
		}

		#endregion
	}
}
